module.exports = function (app, models, $, db, nm) {
    //收藏详情
   app.get('/v2/collect',(req,res) => {
    var query = {
        pageSize:req.query.pageSize || 10,
        pageNum:req.query.pageNum || 1,
        memberId:req.query.memberId,
        type:1
    }
       models.collect.list(query, ret => {
        res.send(ret)
       },{
           join:{
            collectId: {
                   type: 'INNER ',
                   name: 'product',
                   key: '_id',
                   projection: {
                    name: 1,
                    brandId: 1,
                    imgs: 1,
                    description: 1,
                    specification:1,
                    content:1
                   }
               }
           },
           projection: {
            collectId:1,
            _id:1
        }
       })
   })
   //新增收藏
   app.post('/v2/collect', (req, res) => {
       req.body.unitId = req.unitId
       models.collect.find({memberId:req.body.memberId,collectId:req.body.collectId}, ret => {
           if(ret._id == null){
           models.collect.insert(req.body, rett => {
               res.send(rett)
           })}else{
               res.send({errorMsg:'已收藏'})
           }
       })
       
   })
   //删除收藏
   app.delete('/v2/collect',(req,res) => {
       models.collect.remove({_id:req.query._id}, ret => {
           res.send(ret)
       })
   })
   }